﻿package core.ui.dialogs
{
    import core.enum.*;
    import core.event.*;
    import core.image.*;
    import core.ui.controls.*;

    public class HueSaturationDialog extends BitmapOperationDialogBase
    {
        var f:Filter;
        var cb:Checkbox;
        var h:Slidebar;
        var s:Slidebar;
        var l:Slidebar;

        public function HueSaturationDialog(param1:Tuyitu)
        {
            super(param1, "rm_hue_saturation", 240, 240, Action.HueSaturationAdjustment);
            this.f = new Filter();
            this.h = new Slidebar("rm_hue", -180, 180, 200, 0);
            this.h.addEventListener(SliderEvent.DRAG, this.Change, false, 1, true);
            this.h.x = 20;
            this.h.y = 35;
            addChild(this.h);
            this.s = new Slidebar("rm_saturation", -100, 100, 200, 0);
            this.s.addEventListener(SliderEvent.DRAG, this.Change, false, 1, true);
            this.s.x = 20;
            this.s.y = 80;
            addChild(this.s);
            this.l = new Slidebar("rm_lightness", -100, 100, 200, 0);
            this.l.addEventListener(SliderEvent.DRAG, this.Change, false, 1, true);
            this.l.x = 20;
            this.l.y = 125;
            addChild(this.l);
            this.cb = new Checkbox("rm_colorize");
            this.cb.addEventListener(ChangeEvent.CHANGE, this.Change, false, 1, true);
            this.cb.x = 20;
            this.cb.y = 170;
            addChild(this.cb);
            return;
        }// end function

        override public function Change(... args) : void
        {
            args = null;
            if (!locked)
            {
                args = new ColorMatrix();
                if (this.cb.checked)
                {
                    args.Colorize(this.h.value + 180);
                }
                else
                {
                    args.AdjustHue(this.h.value);
                }
                args.AdjustSaturation(1 + this.s.value / 100);
                args.AdjustBrightness(this.l.value / 100 * 255);
                bm.applyFilter(bc, bc.rect, bc.rect.topLeft, args.filter);
                Misc.ApplySelection(bm, bc, selection, offset);
            }
            return;
        }// end function

    }
}
